﻿@model MTQ.Model.Base_UserInfo
@using MTQ.BLL
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout_lay_admin.cshtml";
}

<style>
    body {
        background-color: #ffffff;
    }
</style>

<div class="layui-form layuimini-form">
    <div class="layui-form-item hidden" style="display:none;">
        <label class="layui-form-label required">ID</label>
        <div class="layui-input-block">
            <input type="text" name="User_Id" lay-verify="required" value="@Model.User_Id" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">账户</label>
        <div class="layui-input-block">
            <input type="text" name="User_UserName" lay-verify="required" lay-reqtext="账户不能为空" placeholder="请输入账户" value="@Model.User_UserName" autocomplete="off" class="layui-input">
            <tip>填写账户邮箱地址。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="User_RealName" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="@Model.User_RealName" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">所属公司部门</label>
        <div class="layui-input-block">
            <select id="Department_Id" name="Department_Id" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">职位</label>
        <div class="layui-input-block">
            <select id="Organization_Id" name="Organization_Id" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">角色</label>
        <div class="layui-input-block">
            <select id="Role_Id" name="Role_Id" lay-search="">
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            @{ if (Model.User_Sex == "男")
                {
                    <input type="radio" name="User_Sex" value="男" title="男" checked="">
                    <input type="radio" name="User_Sex" value="女" title="女">
                }
                else
                {
                    <input type="radio" name="User_Sex" value="男" title="男">
                    <input type="radio" name="User_Sex" value="女" title="女" checked="">

                }
            }

        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="User_Email" placeholder="" value="@Model.User_Email" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" name="User_PhoneNumber" placeholder=""  value="@Model.User_PhoneNumber" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="User_Remark" class="layui-textarea" placeholder="请输入备注信息">@Model.User_Remark</textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>

<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url: '/BaseUser/Edit',
                type: 'post',
                dataType: 'text',
                data: data.field,
                success: function (resp) {
                    var json = eval('(' + resp + ')');
                    var index = layer.alert(json.Message, function () {
                        // 关闭弹出层
                        layer.close(index);
                        parent.reloadTable();
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                    //layer.alert(json.Message);
                    //reloadTable();
                },
                error: function (resp) {
                    layer.alert("对不起出错了");
                }
            });


            return false;
        });

        $.ajax({
            type: "GET",
            url: '/Base_Role/SearchAll',
            dataType: 'json',
            success: function (data) {
                $('#Role_Id').empty();
                //selected="selected"
                var selected = '@Model.Role_Id';
                $('#Role_Id').append('<option value="" >请选择角色</option>');
                for (var i = 0; i < data.length; i++) {
                    var option = "";
                    if (selected == data[i].Role_Id) {
                         option = '<option value="' + data[i].Role_Id + '" selected="selected" >' + data[i].Role_Name + '</option>';
                    } else {
                        option = '<option value="' + data[i].Role_Id + '" >' + data[i].Role_Name + '</option>';
                    }
                    $('#Role_Id').append(option);
                }
                form.render('select');
            }
        });


        $.ajax({
            type: "GET",
            url: '/Base_Organization/Search',
            dataType: 'json',
            success: function (data) {
                $('#Organization_Id').empty();
                  var selected = '@Model.Organization_Id';
                $('#Organization_Id').append('<option value="" >请选择职位</option>');
                var d = data.data;
                for (var i = 0; i < d.length; i++) {
                    if (d[i].Organization_Code.length == 3) {

                        var option = "";
                        option = '<optgroup  label="'+d[i].Organization_Name+'">';
                        for (var j = 0; j < d.length; j++) {
                            var selectedhtml = '';
                            if (selected == d[j].Organization_Id) {
                                selectedhtml = ' selected="selected" ';
                            }

                            if (d[j].Organization_Code.substring(0, 3) == d[i].Organization_Code && d[i].Organization_Id !=d[j].Organization_Id) {
                                option += '<option value="' + d[j].Organization_Id + '"  '+selectedhtml+' >' + d[j].Organization_Name + '</option>';
                            }
                        }
                        option += '</optgroup>';
                         $('#Organization_Id').append(option);
                    }
                }
                form.render('select');
            }
        });

        $.ajax({
            type: "GET",
            url: '/Base_Department/Search',
            dataType: 'json',
            success: function (data) {
                 $('#Department_Id').empty();
                  var selected = '@Model.Department_Id';
                $('#Department_Id').append('<option value="" >请选择部门</option>');
                var d = data.data;
                for (var i = 0; i < d.length; i++) {
                    if (d[i].Department_Code.length == 3) {
                        var option = "";
                        option = '<optgroup  label="'+d[i].Department_Name+'">';
                        for (var j = 0; j < d.length; j++) {
                             var selectedhtml = '';
                            if (selected == d[j].Department_Id) {
                                selectedhtml = ' selected="selected" ';
                            }

                            if (d[j].Department_Code.substring(0, 3) == d[i].Department_Code && d[i].Department_Id !=d[j].Department_Id) {
                                option += '<option value="' + d[j].Department_Id + '"  '+selectedhtml+' >' + d[j].Department_Name + '</option>';
                            }
                        }
                        option += '</optgroup>';
                         $('#Department_Id').append(option);
                    }
                }

                form.render('select');
            }
        });

    });
</script>



